<script type="text/javascript">
    function generateBarcode(code=''){
        var value = code;
        var btype = 'code128';
        var renderer = 'css';

        var settings = {
            output:renderer,
            bgColor: '#FFFFFF',
            color: '#000000',
            barWidth: 1,
            barHeight: 50
        };
        $("#print-barcode").html("").show().barcode(value, btype, settings);
    }
    $(document).ready(function() {
        generateBarcode('<?php echo $code; ?>');
    });
</script>
<div id="print-barcode"></div>
<script type="text/javascript">window.print();</script>